package 
{
	import com.control.Controler;
	import com.control.LayerManager;
	import com.control.Menu;
	import com.data.GameData;
	import com.event.EventManager;
	import com.event.PublicEvent;
	import com.greensock.Stats;
	import com.item.Rabbit;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author wen
	 */
	public class Main extends Sprite 
	{
		private var _mapView:MovieClip = null;
		
		private var _menuView:MovieClip = null;
		
		private var _menu:Menu = null;
		
		private var _control:Controler = null;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		/**
		 * 初始化
		 * @param	e
		 */
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			GameData.stage = this.stage;
			
			EventManager.instance.addEventListener(PublicEvent.START, onStartHander);
			EventManager.instance.addEventListener(PublicEvent.BACK, onBackHander);
			
			addRec();
			
		}
		
		//返回主菜单
		private function onBackHander(e:PublicEvent):void 
		{
			_menu.show();
			_control.hide();
		}
		
		//进入地图玩游戏
		private function onStartHander(e:PublicEvent):void 
		{
			GameData.isStart = true;
			
			_menu.hide();
			_control.show();
		}
		
		private function addRec():void 
		{	
			_mapView = new gameMc() as MovieClip;
			_control = new Controler(_mapView);
			
			_menuView = new menuMc();
			_menu = new Menu(_menuView);
			
			//var stat:Stats = new Stats();
			var endDlg:scoreDlg = new scoreDlg();
			
			LayerManager.instance.addToLayer(_menuView, LayerManager.MENU);
			LayerManager.instance.addToLayer(_mapView.mapArea, LayerManager.MAP);
			LayerManager.instance.addToLayer(_mapView.score, LayerManager.DILOG);
			//LayerManager.instance.addToLayer(stat, LayerManager.DEBUG);
		}
	}
}